// pages/wanshan/wanshan.js

var WxParse = require('../../wxParse/wxParse.js');
var dateTimePicker = require('../../wxParse/emojis/dateTimePicker.js');
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    items: [
      {value: '0', name: '单方签', checked: 'true'},
      {value: '1', name: '双方签'},
      {value: '2', name: '多方签'},
    ],
    xianshi1:"display:none",
    date1: '请选择截止日期',
    guanbi:"display:none",
    gr_1:"display:block",
    gr_2:"display:none",
    guanbi1:"display:none",
    array: ['签约扣费方式', '发起方扣费', '签署方自费'],
    index:0,
    shur1:"",
    shur2:"",
    shur3:"",
    shur4:"",
    shur5:"",
    shur6:"",
    shur7:"",
    xianshi:"display:none",
    hetong_user:"",
    page:1,
    date:"选择面试时间",
		dateTimeArray: null,
    dateTime: null,
    startYear: 2000,
    endYear: 2050,
    checked:"true",
    checked1:" "
  },
  changeTime(e) {
    this.setData({ time: e.detail.value });
  },
  changeDateTime(e) {
   const that=this;

   console.log(e.detail)
   this.setData({ dateTime: e.detail.value });
    var aaa1 = that.data.dateTime[0];
    var aaa2 = that.data.dateTime[1];
    var aaa3 = that.data.dateTime[2];
    var aaa4 = that.data.dateTime[3];
    var aaa5 = that.data.dateTime[4];
 
 
    var time1 = that.data.dateTimeArray[0][aaa1];
    var time2 = that.data.dateTimeArray[1][aaa2];
    var time3 = that.data.dateTimeArray[2][aaa3];
    var time4 = that.data.dateTimeArray[3][aaa4];
    var time5 = that.data.dateTimeArray[4][aaa5];
    var time = time1 + '-' + time2 + '-' + time3 + ' ' +time4+ ':' +time5;
    app.globalData.riqi = time
    app.globalData.riqi2 = time
    if(app.globalData.zhi>app.globalData.riqi){
      wx.showModal({
        title: '温馨提示',
        content: '不可以选择之前日期，请注意选择！',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
    console.log(app.globalData.riqi)
  },

  changeDateTimeColumn(e) {
    console.log(22222)
    var arr = this.data.dateTime, dateArr = this.data.dateTimeArray;
    
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
   
    this.setData({
      dateTimeArray: dateArr,
      dateTime: arr
    });
  },
  guanbibin:function(e){
    var that = this;
    this.setData({
      xianshi:"display:none"
    })
 },
  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    app.globalData.xial = e.detail.value
    this.setData({
      index: e.detail.value
    })
  },
  fq_qs:function(e){
    var that = this;
    if(app.globalData.tc_shu==1){
     wx.showModal({
        title: '提示',
        content: '暂时没有套餐，您不可以发起签署！',
      showCancel:false,
        success: function (res) {
            if (res.confirm) {
               wx.switchTab({
                 url:"../index/index"
               })
            } else if (res.cancel) {
                console.log('用户点击取消');
            }
        }
    });
    }else{
      that.setData({
        xianshi:"display:block"
      })
    }
    
    
  },
  bindDateChange1: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    app.globalData.riqi = e.detail.value
    this.setData({
      date1: e.detail.value
    })
  },
  yulan:function(e){
   wx.navigateBack();
  },
  ht_bf1:function(e){
    var that = this;
    console.log(11)
    that.setData({
      currentTab:666
    })
  },
  qshu:function(e){
    app.globalData.qshu =  e.detail.value
  },
  s_chu:function(e){
    var that = this;
    var s_chu = e.currentTarget.dataset.id;
    console.log(s_chu)
    wx.request({
        url: app.globalData.url_l + 'api/order/qu_qianshu', //注意改成自己的服务器请求地址哦！
        method: 'POST',
        data:{
          id:s_chu
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
        },
        success: function (res) {
           console.log(res)
           if(res.data.state==1){
            wx.showToast({
              title: '删除成功!',
              icon: 'none',
              duration: 2000
            })
            that.setData({
              hetong_user:res.data.xinxi
            })
           }else{
            wx.showToast({
              title: '删除失败!',
              icon: 'none',
              duration: 2000
            })
           }
        }
      })  
  },
  switchNav(event){
    var that = this;
    var cur = event.currentTarget.dataset.current;
    console.log(cur)
      
    if (this.data.currentTab == cur) {
        return false;
    } else {
        this.setData({
            currentTab: cur
        })
    }
},
   // 请输入姓名
   txie_x:function(e){
      var that = this;
      app.globalData.txie_x =  e.detail.value
  },
  // 签署方手机号
  txie_x1:function(e){
    var that = this;
    app.globalData.txie_x1 =  e.detail.value
},
  // 签署方邮箱
  txie_x2:function(e){
    var that = this;
    app.globalData.txie_x2 =  e.detail.value
  },
  qy_qs:function(e){
    var that = this;
    app.globalData.qy_qs =  e.detail.value
  },
  qy_qs1:function(e){
    var that = this;
    app.globalData.qy_qs1 =  e.detail.value
  },
  qy_qs2:function(e){
    var that = this;
    app.globalData.qy_qs2 =  e.detail.value
  },
  qy_qs3:function(e){
    var that = this;
    app.globalData.qy_qs3 =  e.detail.value
  },
  tianjia:function(e){
    var that = this;
    var qs_id1 = e.currentTarget.dataset.id;
    app.globalData.qs_id1 = qs_id1
    that.setData({
     guanbi:"display:block"
    })
 },
 shanchu:function(e){
   var that = this;
  var shanchu = e.currentTarget.dataset.id;
 },
 qye1:function(e){
   var that = this;
   app.globalData.type_id = e.currentTarget.dataset.type;
   that.setData({
    qye2:"background:#fff;border:1px solid #f1f1f1;color:#0b5fff",
    qye1:"background:#0b5fff;border:none;color:#fff",
    gr_1:"display:block",
    gr_2:"display:none",
   })
 },
 qye2:function(e){
  var that = this;
  app.globalData.type_id = e.currentTarget.dataset.type;
  that.setData({
   qye1:"background:#fff;border:1px solid #f1f1f1;color:#0b5fff",
   qye2:"background:#0b5fff;border: none;color:#fff",
   gr_2:"display:block",
    gr_1:"display:none",
  })
},
  guanbi:function(e){
     var that = this;
     that.setData({
      guanbi:"display:none"
     })
  },
  guanbi1:function(e){
    var that = this;
    that.setData({
     guanbi1:"display:none"
    })
 },
 tx3:function(e){
  var that = this;
  app.globalData.type_id = e.currentTarget.dataset.type;
  that.setData({
   guanbi1:"display:block",
   guanbi:"display:none"
  })
},
  tx1:function(e){
    var that = this;
    var qianshu_id = e.currentTarget.dataset.id;
     app.globalData.type_id = e.currentTarget.dataset.type;
    that.setData({
      guanbi:"display:none"
     })
    wx.navigateTo({
      url: '../tongxun_l/tongxun_l?chuan_s='+0+"&qianshu_id="+qianshu_id+"&type_id="+app.globalData.type_id+"&qs_id1="+app.globalData.qs_id1,
    })
  },
  radioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)

    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
  },
  /**
   * 生命周期函数--监听页面加载 
   */
  radioChange:function(e){
    this.data.pagee = 1
   
  },
  radioChange:function(e){
    var that = this;
    var id = e.detail.value
    console.log()
    // var id = e.currentTarget.dataset.id
    if(id=='1'){
      app.globalData.riqi = -1;
      
      app.globalData.riqi1 = 0;
      that.setData({
        xianshi1:"display:none",
        checked:"true",
        checked1:" "
      })
    }else{
      app.globalData.riqi = app.globalData.riqi2;
      app.globalData.riqi1 = 1;
      that.setData({
        xianshi1:"display:inline-block",
        checked1:"true",
        checked:" "
      })
    }
  },
  onLoad: function (options) {
     var that = this;
     var that = this;
     app.globalData.riqi2 = ""
     var myDate = new Date();
     myDate.getHours();       // 获取当前小时数(0-23)
     myDate.getMinutes();     // 获取当前分钟数(0-59)
     myDate.getSeconds();     // 获取当前秒数(0-59)
     myDate.getMilliseconds();    // 获取当前毫秒数(0-999)
     myDate.toLocaleDateString();     // 获取当前日期
		 var obj = dateTimePicker.dateTimePicker(myDate.toLocaleDateString().slice(0,4), this.data.endYear);
		////console.log(app.globalData.file7)
		console.log(999999999)
    app.globalData.riqi = -1;
    app.globalData.riqi1 = 0;
   app.globalData.zhi = obj.dateTimeArray[0][obj.dateTime[0]]+'-'+obj.dateTimeArray[1][obj.dateTime[1]]+'-'+obj.dateTimeArray[2][obj.dateTime[2]]+' '+obj.dateTimeArray[3][obj.dateTime[3]]+':'+obj.dateTimeArray[4][obj.dateTime[4]]
    console.log(obj.dateTime)
    console.log(obj.dateTimeArray)
		this.setData({
			dateTime: obj.dateTime,
			dateTimeArray: obj.dateTimeArray,
    });
   
     var ht_id = options.ht_id;
     app.globalData.ht_id = ht_id
     app.globalData.tcid = ""
    //  app.globalData.riqi= ''
     wx.request({
      url: app.globalData.url_l + 'api/order/ws_hetong',
      method: 'post',
      data:{
        ht_id:ht_id
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        that.setData({
          qianyue:res.data.hetong,
          hetong_user:res.data.hetong_user,
          name1:res.data
        })
      }
    })
    
    wx.request({
      url: app.globalData.url_l + 'api/order/kou_xuanze',
      method: 'post',
      data:{
        uid:app.globalData.uid
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if(res.data.qiye==''&&res.data.taocan==''){
           app.globalData.tc_shu = 1
        }else{
          app.globalData.tc_shu = 0
        }
        that.setData({
          qiye:res.data.qiye,
          taocan:res.data.taocan
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  fs_yq:function(e){
    var that = this;
    if(app.globalData.type_id==1){
      if(app.globalData.txie_x == ''||app.globalData.txie_x==null||app.globalData.txie_x==undefined){
        wx.showToast({
          title: '请输入姓名!',
          icon: 'none',
          duration: 2000
        })
      }else if(app.globalData.txie_x1 == ''||app.globalData.txie_x1==null||app.globalData.txie_x1==undefined){
        wx.showToast({
          title: '请输入手机号!',
          icon: 'none',
          duration: 2000
        })
      }else if(app.globalData.txie_x2 == ''||app.globalData.txie_x2==null||app.globalData.txie_x2==undefined){
        wx.showToast({
          title: '请输入邮箱!',
          icon: 'none',
          duration: 2000
        })
      }else{
        wx.request({
          url: app.globalData.url_l + 'api/order/tian_qianshu',
          method: 'post',
          data:{
              uid:app.globalData.uid,
              type:app.globalData.type_id,
              id:app.globalData.qs_id1,
              name:app.globalData.txie_x,
              mobile:app.globalData.txie_x1,
              email:app.globalData.txie_x2
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            console.log(res)
            if(res.data.state==1){
              app.globalData.tx = res.data.xinxi
              app.globalData.txie_x = ''
              app.globalData.txie_x1 = ''
              app.globalData.txie_x2 = ''
              that.setData({
                hetong_user:app.globalData.tx,
                guanbi1:"display:none",
                shur1:"",
                shur2:"",
                shur3:"",
              })
            }else{
              
            }
          }
        })
      }
     
    }else if(app.globalData.type_id==2){
      if(app.globalData.qy_qs == ''||app.globalData.qy_qs==null||app.globalData.qy_qs==undefined){
        wx.showToast({
          title: '请输入经办人姓名!',
          icon: 'none',
          duration: 2000
        })
      }else if(app.globalData.qy_qs1 == ''||app.globalData.qy_qs1==null||app.globalData.qy_qs1==undefined){
        wx.showToast({
          title: '请输入经办人姓名!',
          icon: 'none',
          duration: 2000
        })
      }else if(app.globalData.qy_qs2 == ''||app.globalData.qy_qs2==null||app.globalData.qy_qs2==undefined){
        wx.showToast({
          title: '请输入经办人手机号!',
          icon: 'none',
          duration: 2000
        })
      }else if(app.globalData.qy_qs3 == ''||app.globalData.qy_qs3==null||app.globalData.qy_qs3==undefined){
        wx.showToast({
          title: '请输入邮箱!',
          icon: 'none',
          duration: 2000
        })
      }else{
        wx.request({
          url: app.globalData.url_l + 'api/order/tian_qianshu',
          method: 'post',
          data:{
              uid:app.globalData.uid,
              type:app.globalData.type_id,
              id:app.globalData.qs_id1,
              com_name:app.globalData.qy_qs,
              mobile:app.globalData.qy_qs2,
              email:app.globalData.qy_qs3,
              name:app.globalData.qy_qs1
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            console.log(res)
            if(res.data.state==1){
              app.globalData.tx = res.data.xinxi
              app.globalData.qy_qs = ''
              app.globalData.qy_qs1 = ''
              app.globalData.qy_qs2 = ''
              app.globalData.qy_qs3 = ''
              that.setData({
                hetong_user:app.globalData.tx,
                guanbi1:"display:none",
                shur4:"",
                shur5:"",
                shur6:"",
                shur7:"",
              })
            }else{

            }
          }
        })
      }
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  qure_fq:function(e){
    var that = this;
    that.data.page++;
    console.log(app.globalData.tcid)
    if(that.data.page==2){
      for(var i = 0;i<that.data.hetong_user.length;i++){
        if(that.data.hetong_user[i].name==''||that.data.hetong_user[i].name==null){
          that.data.page = 1
         wx.showToast({
           title: "请确认签署人是否都添加！",
           icon: 'none',
           duration: 2000
         })
         return false;
        }
      
       
      }
      if(that.data.hetong_user.indexOf('') !=''||that.data.hetong_user[i].name.indexOf('') !=null){
        if(app.globalData.riqi1==1){
          if(app.globalData.riqi==""||app.globalData.riqi=='null'||app.globalData.riqi=='undefined'){
            that.data.page = 1
             wx.showToast({
               title: '请选择时间!',
               icon: 'none',
               duration: 2000
             })
           }else if(app.globalData.zhi>app.globalData.riqi){
            wx.showModal({
              title: '温馨提示',
              content: '不可以选择之前日期，请注意选择！',
              showCancel:false,
              success (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          }else if(app.globalData.tcid==''||app.globalData.tcid==null||app.globalData.tcid==undefined){
             wx.showToast({
               title: '请选择套餐!',
               icon: 'none',
               duration: 2000
             })
             that.data.page = 1
           }else{
             wx.request({
               url: app.globalData.url_l + 'api/order/koukuan123',
               method: 'post',
               data:{
                   uid:app.globalData.uid,
                   type:app.globalData.tc_id1,
                   ht_id:app.globalData.ht_id,
                   id:app.globalData.tcid,
                   qs_shuoming:app.globalData.qshu,
                   end_time:app.globalData.riqi
               },
               header: {
                 'content-type': 'application/x-www-form-urlencoded'
               },
               success: function (res) {
                 console.log(res)
                 if(res.data.code==1){
                  app.globalData.tcid = ""
                  app.globalData.riqi= ''
                   wx.showToast({
                     title: res.data.msg,
                     icon: 'none',
                     duration: 2000
                   })
                   setTimeout(function(){
                    that.data.page=1
                     wx.switchTab({
                      
                       url: '../hetong/hetong',
                     })  
                   },3000)
                 }else{
                  that.data.page=1;
                  wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                    duration: 2000
                  })
                 }
               }
             })
           }
        }else{
         if(app.globalData.tcid==''||app.globalData.tcid==null||app.globalData.tcid==undefined){
             wx.showToast({
               title: '请选择套餐!',
               icon: 'none',
               duration: 2000
             })
             that.data.page = 1
           }else{
             wx.request({
               url: app.globalData.url_l + 'api/order/koukuan123',
               method: 'post',
               data:{
                   uid:app.globalData.uid,
                   type:app.globalData.tc_id1,
                   ht_id:app.globalData.ht_id,
                   id:app.globalData.tcid,
                   qs_shuoming:app.globalData.qshu,
                   end_time:app.globalData.riqi
               },
               header: {
                 'content-type': 'application/x-www-form-urlencoded'
               },
               success: function (res) {
                 console.log(res)
                 if(res.data.code==1){
                  app.globalData.tcid = ""
                  app.globalData.riqi= ''
                   wx.showToast({
                     title: res.data.msg,
                     icon: 'none',
                     duration: 2000
                   })
                   setTimeout(function(){
                    that.data.page=1
                     wx.switchTab({
                      
                       url: '../hetong/hetong',
                     })  
                   },3000)
                 }else{
                  that.data.page=1;
                  wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                    duration: 2000
                  })
                 }
               }
             })
           }
        }
      
      }
    }else{
      that.data.page=1
    }
   
   
   
  },
  switchNav1(event){
    var that = this;
    var cur = event.currentTarget.dataset.current1; 
    var tc_id1 = event.currentTarget.dataset.id; 
    console.log(cur)
    if(cur==0){
      app.globalData.tcid = ''
    }else{
      app.globalData.tcid = cur
    }
    app.globalData.tc_id1 = tc_id1
    console.log(app.globalData.tcid)
    var singleNavWidth1 = this.data.windowWidth / 5;
    var tu = (cur - 2) * singleNavWidth1
    this.setData({
      navScrollLeft1: (cur - 2) * singleNavWidth1+40
    })      
    if (this.data.currentTab1 == cur) {
        return false;
    } else {
        this.setData({
            currentTab1: cur
        })
    }
  },
  onShow: function () {
    var that = this;
    if(app.globalData.tx==''){

    }else{
      that.setData({
        hetong_user:app.globalData.tx
      })

    }
    
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})